#ifndef __GND_WATCH_DOG_SOURCE_H__
#define __GND_WATCH_DOG_SOURCE_H__

#include <glibmm/main.h>

namespace Gnodroid {

    /**看门狗Source类，长时间不喂狗导致狗饥饿执行指定任务
     */
    class WatchDogSource :
        public Glib::Source
    {
    public:
        /** 创建一个看门狗
         * @param slotCb    饥饿回调
         * @param timeout   超时时间
         * @return
         */
        static Glib::RefPtr<WatchDogSource>
        create(sigc::slot<bool> slotCb, gint64 timeout);

        /** 喂狗，会重置超时的剩余时间
         */
        void feedDog();
    protected:
        WatchDogSource(sigc::slot<bool> slotCb, gint64 timeout);
        bool prepare(int &timeout);
        bool check();
        bool dispatch(sigc::slot_base *slot);
    private:
        gint64 m_iTimeout;
        gint64 m_iLastTime; //start time
        sigc::slot<bool> m_slotCb;
    };

}


#endif
